﻿//根据requirejs的规范进行初始化
//路由页面
define(['app'], function (app) {
    app.config(function ($stateProvider, $urlRouterProvider, $controllerProvider, $compileProvider) {
        app.registerController = $controllerProvider.register;
        app.directive = $compileProvider.directive;
        //动态加载JS的代码进行JS地址的拼接
        app.loadJs = function (js) {
            return function ($rootScope, $q) {
                var def = $q.defer(),
					deps = [];
                angular.isArray(js) ? (deps = js) : deps.push(js);
                require(deps, function () {
                    $rootScope.$apply(function () {
                        def.resolve();
                    });
                });
                return def.promise;
            };
        }
        //初始化页面
        $urlRouterProvider.otherwise('/index');
        $stateProvider.state('index', {
            //页面请求的url地址
            url: '/index',
            views: {
                '': {
                    templateUrl: 'index.html', //请求地址所调用的HTML页面
                    controller: 'view.home.index',//当前HTML页面的Angular Controller
                    resolve: {
                        deps: app.loadJs('index.js')//申明我的当前页面使用的JS是那个
                    }
                }
            }
        });
    });
    appFactory(app);
})